import Vue from 'vue'
import App from './App.vue'
import Find from './views/Find.vue'
import My from './views/My.vue'
import Part from './views/Part.vue'
import NotFound from './views/NotFound.vue'
import Recommend from './views/Second/Recommend.vue'
import Ranking from './views/Second/Ranking.vue'
import SongList from './views/Second/SongList.vue'

import VueRouter from 'vue-router'
Vue.use(VueRouter)

const routes = [
  {
    path: "/", // 默认hash值路径
    redirect: "/find" // 重定向到/find
  },
  {
    path: '/find',
    component: Find,
    name: "Find",
    children: [
      {
        path: "recommend",
        component: Recommend
      },
      {
        path: "ranking",
        component: Ranking
      },
      {
        path: "songlist",
        component: SongList
      }
    ]
  },
  {
    path: '/my',
    component: My,
    name: "My",
  },
  {
    path: '/part',
    component: Part,
    name: "Part",
  },
  {
    path: '/part/:username',
    component: Part,
  },
  {
    path: '*',
    component: NotFound,
  }

]

const router = new VueRouter({
  routes
})

// 全局前置守卫
const isLogin = false; // 登录状态(未登录)
router.beforeEach((to, from, next) => {
  if (to.path === '/my' && isLogin === false) {
    alert("请登录")
    next(false) // 阻止路由跳转
  } else {
    next()
  }
})

Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App),

}).$mount('#app')
